package json

import (
	"bytes"
	"errors"
	"fmt"
	"github.com/json-iterator/go"
)

type Json struct {
}

func (j *Json) StructToJson(v interface{}) string {

	var json = jsoniter.ConfigCompatibleWithStandardLibrary
	data, err := json.Marshal(v)

	if err != nil {
		fmt.Println(err)
		return ""
	}

	return string(data)
}

func (j *Json) JsonToStruct(str string, object interface{}) error {

	if str == "" {
		return errors.New("str is empty")
	}

	var json = jsoniter.ConfigCompatibleWithStandardLibrary
	json.Unmarshal([]byte(str), object)

	return nil
}

func (j *Json) StringJoin(args ...string) string {

	if len(args) == 0 {
		return ""
	}
	var buffer bytes.Buffer

	for _, arg := range args {
		buffer.WriteString(arg)
	}

	return buffer.String()
}
